<?php

namespace Api\Model;

use Think\Model;

class ReplyModel extends Model {

    function addComment($post_id, $icon, $user_id) {
        $data = array(
            'post_id' => $post_id,
            'user_id' => $user_id,
            'icon' => $icon,
            'createtime' => date('Y-m-d H:i:s')
        );
        return $this->add($data);
    }

    function getComment($post_id, $user_id) {
        $where = array(
            'post_id' => $post_id,
            'user_id' => $user_id
        );
        return $this->where($where)->find();
    }

    function addIcons($post_id, $icons) {
        $data['post_id'] = $post_id;
        foreach ($icons as $key => $value) {
            $data[$key] = $value;
        }
        return M('Icons')->add($data);
    }

    function upIcons($post_id, $icons) {
        $where = array('post_id' => $post_id);
        return M('Icons')->where($where)->save($icons);
    }

    function getIcons($post_id) {
        $where = array('post_id' => $post_id);
        return M('Icons')->where($where)->find();
    }

    function getList($post_id, $start = 0, $limit = 10) {
        $where = array('post_id' => $post_id);
        $limit = $start . ',' . $limit;
        return $this->where($where)->limit($limit)->select();
    }

}
